package me.pinion.model.message;


import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public enum MessageType {
    SYSTEM, COMMENT, REPLY, LETTER, LIKE, FAVORITE;

    public static int getTypeId(MessageType type){
        Record record = Db.findFirst("SELECT * FROM msg_type WHERE name=?", type.name());
        if (record == null){
            record = new Record();
            record.set("name", type.name());
            Db.save("msg_type", record);
        }
        int id = 0;
        try{
            id = record.getInt("id");
        }catch (Exception e){
            id = record.getLong("id").intValue();
        }
        return id;
    }
}
